package com.xq.connection;

import org.I0Itec.zkclient.ZkClient;
import org.apache.zookeeper.CreateMode;

/**
 * 集群版连接ZK测试，将linux的zk端口分别为2181,2182,2183
 * @author 卡布奇诺
 */
public class TestZkServerCluster {
    /**
     * ZK连接URL
     */
    private static final String SERVER_IP = "192.168.2.120:2181,192.168.2.120:2182,192.168.2.120:2183";

    /**
     * zk客户端对象
     */
    private static ZkClient zkClient = null;

    static {
        // 初始化zk客户端对象
        zkClient = new ZkClient(SERVER_IP,10000,10000);
    }

    public static void main( String[] args ) {
        // 1、创建节点
        zkClient.create("/java","http", CreateMode.PERSISTENT);
        // 2、修改
        zkClient.writeData("/java","https");
        // 3、查询
        Object data = zkClient.readData("/java");
        System.out.println(data);
        // 4、删除
        zkClient.delete("/java");
        System.out.println("操作成功ZkClient");
    }
}
